/**
 * Created by gaoyj on 2018/6/28.
 */
window.onload = function (ev) {
    topbar.hide();
};
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
if (month < 10) {
    month = "0" + month;
}
if (day < 10) {
    day = "0" + day;
}
var _start = myDate.getFullYear() + '-' + month + '-' + day + " 00:00:00";
var _end = myDate.getFullYear() + '-' + month + '-' + day + " 23:59:59";
$("#startTime").val(_start);
$("#endTime").val(_end);
laydate.render({
    elem: '#startTime',
    type: 'datetime',
});
laydate.render({
    elem: '#endTime' //指定元素
    , type: 'datetime',
});
var adminRole = roleCheck();
$('#dataTable').bootstrapTable({
    url: '/UserFeedbackController/queryFeedbackPage',
    height: $(window).height() - 200,
    pageSize: 30,
    pageList: [30, 50, 100],
    clickToSelect: true,
    singleSelect: true,
    queryParams: queryParams,
    queryParamsType: '',
    sidePagination: 'server',
    responseHandler: function (res) {
        return {
            "total": res.total,//总页数
            "rows": res.resultList   //数据
        };
    },
    onClickRow: function (row) {
        if (row.account != null && row.account != '') {
            $("#account_field" + row.id).html(row.account);
        }
    },
    columns: [
        {
            checkbox: true
        }, {
            width: '3px',
            align: 'center',
            formatter: function (v, row, index) {
                return index + 1
            }
        },
        {
            field: "account", title: '会员编号', width: 100, align: 'center',
            formatter: function (v, o) {
                return copyAddon(v) + (adminRole == 1 ? v : userAccountHidden(o.account, o.id));
            }
        },
        {field: "name", title: '会员名称', width: 100, align: 'center'},
        {field: "userPhone", title: '联系电话', width: 100, align: 'center'},
        {
            field: "status", title: '处理状态', width: 70, align: 'center', formatter: function (v, o) {
            return {0: "未处理", 1: "处理中", 2: "处理完成"}[v];
        }
        },
        {
            field: "feedBackTime",
            title: '反馈时间',
            width: 130,
            align: 'center',
            formatter: function (v, o) {
                return format(v);
            }
        },
        {
            field: "dealTime", title: '处理时间', width: 130, align: 'center',
            formatter: function (v, o) {
                return format(v);
            }
        },
        {field: "admin", title: '审核人', width: 70, align: 'center'},
        {field: "feedback", title: '意见反馈', width: 190, align: 'center'},
        {field: "remark", title: '处理备注', width: 190, align: 'center'}
    ]
});

$("#search").click(function () {
    var timeAdd = new Date($("#startTime").val());
    var timeEnd = new Date($("#endTime").val());
    if (timeAdd > timeEnd) {
        layer.msg("开始时间不能大于结束时间");
        return false;
    }
    $("#dataTable").bootstrapTable("refresh");
});

$("#modifyFeedback").click(function () {
    var rows = $('#dataTable').bootstrapTable("getSelections");
    if (rows == null || rows.length === 0) {
        layer.msg("请选择要操作的数据");
        return;
    }
    $("#hidId").val(rows[0].id);
    $("#modifyFeedbackModal").modal("show");
})
$("#modifyFeedbackSubmit").click(function () {
    $.post("/UserFeedbackController/modifyFeedback", $("#modifyFeedbackForm").serialize(), function (data) {
        $("#modifyFeedbackModal").modal("hide");
        layer.msg(data.message)
        $("#dataTable").bootstrapTable("refresh");
    }).error(function (e) {
        layer.msg("操作失败")
    });
});

function queryParams(params) {
    return {
        size: params.pageSize,
        page: params.pageNumber,
        startTime: $("#startTime").val(),
        endTime: $("#endTime").val(),
        account: $.trim($("#account").val()),
        userPhone: $.trim($("#phone").val()),
        status: $("#status").val(),
        admin: $.trim($("#admin").val()),
        feedback: $.trim($("#feedback").val()),
        remark: $.trim($("#remark").val()),
    };
}

